/*
 *Copyright © 2015 HanHai
 *湖北汉海拍卖集团
 *All rights reserved.
 */
package com.hanhai.zrb.backend.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.api.biz.service.CityInfoService;
import com.hanhai.zrb.model.project.CityInfo;

@Controller
@RequestMapping("cityinfo")
public class CityInfoController extends BaseController {

	@Resource
	private CityInfoService cityInfoService;

	@RequestMapping(value="findAllProvince",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String findAllProvince() {
		List<CityInfo> list = cityInfoService.findAllProvince();
		return JSONObject.toJSONString(list);
	}

	@RequestMapping(value="findCityProvince",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String findCityByProvince(String code){
		List<CityInfo> list = new ArrayList<CityInfo>();
		CityInfo cityInfo = new CityInfo();
		if ("110000".equals(code)) {// 北京
		// cityInfo.setPostcode(code);
		// cityInfo.setCityName("北京市");
		// list.add(cityInfo);
			list = cityInfoService.findCountryProvince(code.substring(0, 2),
					"北京市");
		} else if ("120000".equals(code)) {// 天津市
		// cityInfo.setPostcode(code);
		// cityInfo.setCityName("天津市");
		// list.add(cityInfo);
			list = cityInfoService.findCountryProvince(code.substring(0, 2),
					"天津市");
		} else if ("500000".equals(code)) {// 重庆市
		// cityInfo.setPostcode(code);
		// cityInfo.setCityName("重庆市");
		// list.add(cityInfo);
			list = cityInfoService.findCountryProvince(code.substring(0, 2),
					"重庆市");
		} else if ("310000".equals(code)) {// 上海
		// cityInfo.setPostcode(code);
		// cityInfo.setCityName("上海市");
		// list.add(cityInfo);
			list = cityInfoService.findCountryProvince(code.substring(0, 2),
					"上海市");
		} else if ("710000".equals(code)) {// 台湾省
			cityInfo.setPostcode(code);
			cityInfo.setCityName("台湾省");
			list.add(cityInfo);
		} else if ("810000".equals(code)) {// 香港特别行政区
			cityInfo.setPostcode(code);
			cityInfo.setCityName("香港特别行政区");
			list.add(cityInfo);
		} else if ("820000".equals(code)) {// 澳门特别行政区
			cityInfo.setPostcode(code);
			cityInfo.setCityName("澳门特别行政区");
			list.add(cityInfo);
		} else {
			list = cityInfoService.findCityProvince(code.substring(0, 2));
		}

		return JSONObject.toJSONString(list);
	}

	@RequestMapping(value="findCountryProvince",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String findDistrictByCity(String code) {
		//List<District> list =districtService.findDistrictByCity(code);//区县
				List<CityInfo> list = new ArrayList<CityInfo>();
				CityInfo cityInfo = new CityInfo();
				 if( "810000".equals(code)){//香港特别行政区
					cityInfo.setPostcode(code);
					cityInfo.setCityName("香港特别行政区");
					list.add(cityInfo);
				 }else if( "820000".equals(code)){//澳门特别行政区
					cityInfo.setPostcode(code);
					cityInfo.setCityName("澳门特别行政区");
					list.add(cityInfo);
				 }else if( "710000".equals(code)){//台湾省
					cityInfo.setPostcode(code);
					cityInfo.setCityName("台湾省");
					list.add(cityInfo);
				 }
				 else{
					CityInfo cinfo = cityInfoService.selectByPostcode(code);
				 	list = cityInfoService.findCountryProvince(code.substring(0, 2),cinfo.getCityName());
				 }
		return JSONObject.toJSONString(list);
	}

}
